package thread.base;

/**
 * Created by mHandler on 2018/5/27 0027.
 * Description:interrupt结合return停止线程
 * tips:建议使用抛异常停止以便处理后续信息以及不会出现多个return污染
 */
public class Thread_interrupt_return extends Thread{
    @Override
    public void run() {
        super.run();
        while (true){
            if (this.isInterrupted()){
                System.out.println("停止线程");
                return;
            }
            System.out.println("timer = "+System.currentTimeMillis());
        }
    }

    public static void main(String[] args) throws InterruptedException{
        Thread_interrupt_return thr = new Thread_interrupt_return();
        thr.start();
        Thread.sleep(1000);
        thr.interrupt();
    }
}
